/*
2019.9.16
*/
#include<iostream>
#include<string.h>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Solution {
public:
    static int strStr(string haystack, string needle) 
	{
		if(haystack.size()<needle.size())
		{
			return -1;
		}
		if(needle.size()==0)
		{
			return 0;
		}
        for(int i=0;i<=haystack.size()-needle.size();i++)
        {
        	if( haystack[i]==needle[0]&&is_equal(haystack,needle,i) )
        	{
        		return i;
			}	
		}
		return -1;
    }


	static bool is_equal(string str1,string str2,int n)
	{
		if(str1.size()-n<str2.size())
		{
			return false;
		}
		
		for(int i=0;i<str2.size();i++)
		{
			if(str1[n]!=str2[i])
			{
				return false;
			}
			n++;
		}
		return true;
	} 
};

int main()
{
	Solution solution;
	string haystack = "mississippi", needle = "mississippi";
	int a=solution.strStr(haystack,needle) ;
//	cout<<solution.is_equal(haystack,needle,0)<<endl;
	cout<<a<<endl;
	return 0;
}
